# -*- coding: utf-8 -*-
# __author__ = 'xxx'
# env: python 3.9.2 kubernetes  22.6.0
# fuction: 把配置文件直接写入到字典中

from  kubernetes import client,config
import yaml


def getconfig():

    # load k8s config
    #config.load_kube_config()

    # assign file path load and load
    #config.load_kube_config(config_file="/home/appuse/fortmp/config")


    # load  config from  dict
    # yamlfile = open("/opt/devlopuse/k8sl01/k801/k8sconfig/231/config")
    #yamltodic = yaml.load(yamlfile, Loader=yaml.FullLoader)

    # config.load_kube_config_from_dict(yamltodic)

    # 字典形式的 config
    configdirct=""

    config.load_kube_config_from_dict(configdirct)

    #print title

    print("Supported APIs (* is preferred version):")

    # format print get core version
    print("%-40s %s" %
          ("core", ",".join(client.CoreApi().get_api_versions().versions)))


    # show  Api group
    # 显示 API 群组
    for api in client.ApisApi().get_api_versions().groups:
        versions = []
        for v in api.versions:
            name = ""
            if v.version == api.preferred_version.version and len(
                    api.versions) > 1:
                name += "*"
            name += v.version
            versions.append(name)
        print("%-40s %s" % (api.name, ",".join(versions)))


getconfig()

